Skip to content

[BugFix] Fixes register_save_hook bug#3340

Merged
vmoens merged 3 commits into
pytorch:mainfrom
ParamThakkar123:fix/register_hook
Jan 19, 2026
Merged

[BugFix] Fixes register_save_hook bug#3340
vmoens merged 3 commits into
pytorch:mainfrom
ParamThakkar123:fix/register_hook

Conversation

@ParamThakkar123

Copy link
Copy Markdown
Contributor

Description

Describe your changes in detail.

Add register_save_hook and register_load_hook methods to Storage in checkpointer.py to fix attribute errors occuring while using LazyMemmapStorage

Motivation and Context

Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax close #15213 if this solves the issue #15213

Fixes #3247

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of examples)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@pytorch-bot

pytorch-bot Bot commented Jan 17, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3340

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 17, 2026

@vmoens vmoens left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ParamThakkar123 👋

Thank you so much for tackling this bug and additions!
This was a real gap in the API and your PR correctly identified the issue from #3247.

I've gone ahead and patched a few things in your implementation – my apologies for stepping on your code, but I wanted to make sure the fix was solid before merging. I hope you don't mind!

Changes I made:

  • Moved the hook lists from class-level to instance-level in StorageCheckpointerBase.__init__() (the original class-level lists would have caused hooks to be shared across all checkpointer instances)
  • Consolidated the _get_shift_from_last_cursor and shift/is_full computation into the base class to avoid duplication between TensorStorageCheckpointer and FlatStorageCheckpointer
  • Simplified Storage.register_save_hook() to just forward to the checkpointer
  • Updated the test to avoid local imports and use a proper class instead of mock.Mock()

The core idea of your fix was exactly right – we just needed to plug a few architectural details. Thanks again for the contribution!

@vmoens vmoens left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ParamThakkar123 👋

Thank you so much for tackling this bug and additions!
This was a real gap in the API and your PR correctly identified the issue from #3247.

I've gone ahead and patched a few things in your implementation – my apologies for stepping on your code, but I wanted to make sure the fix was solid before merging. I hope you don't mind!

Changes I made:

  • Moved the hook lists from class-level to instance-level in StorageCheckpointerBase.__init__() (the original class-level lists would have caused hooks to be shared across all checkpointer instances)
  • Consolidated the _get_shift_from_last_cursor and shift/is_full computation into the base class to avoid duplication between TensorStorageCheckpointer and FlatStorageCheckpointer
  • Simplified Storage.register_save_hook() to just forward to the checkpointer
  • Updated the test to avoid local imports and use a proper class instead of mock.Mock()

The core idea of your fix was exactly right – we just needed to plug a few architectural details. Thanks again for the contribution!

@vmoens vmoens force-pushed the fix/register_hook branch from 1b2c730 to ce6806d Compare January 18, 2026 22:09
@ParamThakkar123

Copy link
Copy Markdown
Contributor Author

Thank you so much @vmoens 🫡 . Happy to contribute and work more on making this repo better

@vmoens vmoens added the bug Something isn't working label Jan 19, 2026
@vmoens vmoens merged commit 9ee9e90 into pytorch:main Jan 19, 2026
46 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 'Storage' object has no attribute 'register_save_hook'

2 participants